package com.eelye.util.winui.window;

import com.eelye.util.winui.manager.ProcessManager;
import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.WinNT.HANDLE;

public class Process {

    private HANDLE hHandle;

    private String path;

    public Process(HANDLE hHandle, String path) {
        this.hHandle = hHandle;
        this.path = path;
    }

    public Process(HANDLE hHandle) {
        this.hHandle = hHandle;
    }

    public HANDLE getHandle() {
        return hHandle;
    }

    /**
     * 注意，由于权限限制，大部分情况下，只能打开的进程HANDLE才能关闭。
     * @return
     */
    public boolean terminate() {
        return ProcessManager.terminateProcess(this);
    }

    public int getId() {
        return Kernel32.INSTANCE.GetProcessId(hHandle);
    }
}
